package com.intct.phoenix;

import java.sql.*;

/**
 * @author gufg
 * @since 2025-06-19 09:36
 */
public class QueryData {
    public static void main(String[] args) throws Exception {
        // URL
        String url = "jdbc:phoenix:jd-node:2181";

        // 加载驱动类
        Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");

        // 创建 与Phoneix连接
        Connection connection = DriverManager.getConnection(url);

        String sql = "select id, f1.name as f1_name, f1.age, f2.name as f2_name from intct_80_api.t91";

        // 预执行，可以有效解决SQL注入漏洞
        PreparedStatement preparedStatement = connection.prepareStatement(sql);

        // 执行SQL查询
        ResultSet resultSet = preparedStatement.executeQuery();

        // 打印
        while (resultSet.next()) {
            System.out.println(resultSet.getString("f1_name"));
        }

        // 关闭资源
        preparedStatement.close();
        resultSet.close();
        connection.close();
    }
}
